package com.xckj.cycling.activity;

import android.annotation.SuppressLint;
import android.content.Intent;
import android.text.TextUtils;
import android.view.View;

import com.xckj.cycling.R;
import com.xckj.cycling.databinding.ActivityLoginBinding;
import com.xckj.cycling.framework.BaseActivity;
import com.xckj.cycling.global.Constant;
import com.xckj.cycling.utils.CheckFormatUtil;

import java.util.Objects;

/**
 * @Author: ChenYao
 * @Describe: 登录
 * @Date: 2023/2/25 23:40
 */
public class LoginActivity extends BaseActivity<ActivityLoginBinding> {


    @Override
    protected int loadLayout() {
        return R.layout.activity_login;
    }

    @Override
    protected void initData() {
    }

    @Override
    protected void setListener() {
        dataBinding.btnLogin.setOnClickListener(this);
        dataBinding.btnRegister.setOnClickListener(this);
        dataBinding.btnForgetPassword.setOnClickListener(this);
        dataBinding.btnFacebookLogin.setOnClickListener(this);
        dataBinding.btnGoogleLogin.setOnClickListener(this);
    }

    @SuppressLint("NonConstantResourceId")
    @Override
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.btn_login:
                login();
                break;
            case R.id.btn_register:
                register();
                break;
            case R.id.btn_forget_password:
                forgetPassword();
                break;
            case R.id.btn_facebook_login:
                facebookLogin();
                break;
            case R.id.btn_google_login:
                googleLogin();
                break;
            default:
                break;
        }

    }

    private void login() {
        String mailbox = dataBinding.etMailbox.getText().toString();
        String password = Objects.requireNonNull(dataBinding.etPassword.getText()).toString();
        if (TextUtils.isEmpty(mailbox)) {
            showMessage(getString(R.string.mailbox_hint));
            return;
        }
        if (!CheckFormatUtil.isMailbox(mailbox)) {
            showMessage(getString(R.string.mailbox_error));
            return;
        }
        if (TextUtils.isEmpty(password)) {
            showMessage(getString(R.string.password_hint));
            return;
        }
        if (password.length() <= Constant.PASSWORD_MIN_LENGTH) {
            showMessage(getString(R.string.password_length_error));
            return;
        }
        login(mailbox, password);

    }

    private void login(String mailbox, String password) {
    }

    private void register() {
        startActivity(new Intent(this, RegisterActivity.class));
    }

    private void forgetPassword() {
        startActivity(new Intent(this, ForgetPasswordActivity.class));
    }

    private void facebookLogin() {
    }

    private void googleLogin() {
    }
}
